package j2024.j202410;

import java.util.HashMap;

public class j1004 {
    public boolean wordPattern(String pattern, String str) {
        HashMap<Character,String> map = new HashMap<>();
        String[] array = str.split(" ");
        if(pattern.length() != array.length){
            return false;
        }
        for(int i = 0; i < pattern.length();i++){
            char key = pattern.charAt(i);
            if(map.containsKey(key)){
                if(!map.get(key).equals(array[i])){
                    return false;
                }
            }else{
                //判断 value 中是否存在
                if(map.containsValue(array[i])){
                    return false;
                }
                map.put(key, array[i]);
            }
        }
        return true;
    }
}
